<template>
  <div class="curvePriceDiv">
    <el-form-item  :label="labelName"   v-model="calcPricingParam">
      <el-row style="display: inline-flex">
        <el-col :span="5">
          <dictCombox v-model="calcPricingParam.curveType" :clearable="false" dictType="curveType"/>
        </el-col>

        <el-col :span="19" v-show="calcPricingParam.curveType=='fix'">
          <el-col :span="15">
            <Numberinput v-model="calcPricingParam.rate" append="%" precision="3" :min="''" format="#,##0.####"/>
          </el-col>
          <el-col :span="9">
            <dictCombox v-model="calcPricingParam.dayCount" prop='disDayCount' :label="xxxx" dictType="dayCounterPP"/>
          </el-col>
        </el-col>

        <el-col :span="19" v-show="calcPricingParam.curveType!='fix'">
          <baseCombox :url="props.url" clearable
                      :labelField="props.labelField"
                      :valueField="props.valueField"
                      prop="disIrcCode"

                      :style="{width: '100%'}" v-model="calcPricingParam.code"></baseCombox>
        </el-col>
      </el-row>
    </el-form-item>

  </div>

</template>

<script setup expose name="curvePriceCombox">

import {reactive, ref, watch, toRefs, getCurrentInstance, inject} from 'vue'
import Numberinput from '@/lz/base/number'
import baseCombox from '@/lz/base/baseCombox'
import dictCombox from '@/lz/base/dictCombox'
import InputAmount from '@/lz/base/InputAmount'
import useSysConfigStore from '@/store/modules/sysConfig'
const {proxy} = getCurrentInstance()
const props = defineProps({
  url: {
    type: String,
    default: '/irCurve/queryIrCurveList.action'
  },
  index: {
    type: String,
    default: ''
  },
  type: {
    type: String,
    default: 'ircurve'
  },
  labelName: {
    type: String,
    default: '无风险利率'
  },
  labelField: {
    type: String,
    default: ''
  },
  valueField: {
    type: String,
    default: ''
  },
  calcPricingParam: {
    type: Object,
    default: {}
  }
})
const {url, labelName} = toRefs(props)
const calcPricingParam = reactive({
  rate: '0',
  code: '',
  curveType: 'fix',
  dayCount: 'Actual/365'
})
const setCalcPricingParam = (value) => {
  /*先清空*/
    calcPricingParam.rate= '0',
    calcPricingParam.code= '',
    calcPricingParam.curveType= 'fix',
    calcPricingParam.dayCount= 'Actual/365'
  if (Boolean(value)) {
    if (!Boolean(value.rate) && !Boolean(value.code)) {
      calcPricingParam.curveType = 'fix'
      calcPricingParam.rate = ''
      calcPricingParam.dayCount = ''
      return
    }
    if (Boolean(value.rate == '' || value.code)) {
      calcPricingParam.curveType = 'float'
      calcPricingParam.code = value.code
    } else {
      calcPricingParam.curveType = 'fix'
      calcPricingParam.rate = proxy.lsh.multiply(value.rate, 100)
      calcPricingParam.dayCount = value.dayCount
    }
  }
}
const getCalcPricingParam = (calcType) => {
  if (calcPricingParam.curveType == 'fix') {
    let sysConfigByDefVal = useSysConfigStore().getSysConfigByDefVal("calc.param.socInterest","false");
    return {
      rate: proxy.lsh.round(proxy.lsh.divide(Number(calcPricingParam.rate), 100), 5),
      type: Boolean(sysConfigByDefVal)? "2" : "0",
      dayCount: calcPricingParam.dayCount
    }
  }else {
    return {
      code: calcPricingParam.code
    }
  }

}

const getIndexRef = inject('getIndexRef')

//指定 ref  暴露断点
defineExpose({
  calcPricingParam,
  setCalcPricingParam, getCalcPricingParam
})
</script>
<style scoped>
.curvePriceDiv{
  /*background-color: #F0F5F0*/
}
</style>
